<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="./script/rem.js"></script>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>

    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
</head>
<body>

<header class="head" style="padding-top:0.4rem;">
    <div class="head-l" tapmode onclick="closeWin()"><i class="fa fa-angle-left"></i></div>
    <h3>充值记录</h3>
    <div class="head-r"></div>
</header>

<!-- 无记录 -->
<div class="wallet-d-no mt100" id="wallet-record">
    <img src="image/wallet-d-no.png">
    <p>无充值记录啦！</p>
</div>

<div id="list-id" style="display:none;">
    <!-- <ul class="wallet-list">
        <li>
            <dl>
                <dt>充值<span>￥500</span></dt>
                <dd>2018-02-05 20:21</dd>
            </dl>
            <p>1800赚石</p>
        </li>
        <li>
            <dl>
                <dt>充值<span>￥500</span></dt>
                <dd>2018-02-05 20:21</dd>
            </dl>
            <p>1800赚石</p>
        </li>
        <li>
            <dl>
                <dt>充值<span>￥500</span></dt>
                <dd>2018-02-05 20:21</dd>
            </dl>
            <p>1800赚石</p>
        </li>
        <li>
            <dl>
                <dt>充值<span>￥500</span></dt>
                <dd>2018-02-05 20:21</dd>
            </dl>
            <p>1800赚石</p>
        </li>
        <li>
            <dl>
                <dt>充值<span>￥500</span></dt>
                <dd>2018-02-05 20:21</dd>
            </dl>
            <p>1800赚石</p>
        </li>
    </ul> -->
</div>

<script type="text/template" id="wallet-list-id">
    {{~it.data:value:index}}
    <ul class="wallet-list">
        <li>
            <dl>
                <dt>充值<span>￥{{=value.integral}}</span></dt>
                <dd>{{=value.time}}</dd>
            </dl>
            <p>{{=value.integral}}赚石</p>
        </li>
    </ul>
    {{~}}
</script>


</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/index.js"></script>
<script type="text/javascript">
    apiready = function(){
        history_integral();
        pullLoading();
        initRefresh();
    }

    function history_integral(more){
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });
        if (more) {
            page += 1;
        }else{
            page = 1;
        }
        var token = $api.getStorage('token');
        api.ajax({
            url: webAddress + '/api/user/wallet/history/integral',
            method: 'get',
            data: {
                values: { 
                    page: page,
                    row: row,
                },
            },
            headers: {
                Authorization: 'Bearer ' + token,
                Accept: 'application/json',
            },
        },function(ret, err){
            if (ret) {
                api.hideProgress();
                // alert( JSON.stringify( ret ) );
                if (ret.data && ret.data != "") {
                  templateFun(ret,more);
                }
            } else {
                // alert( JSON.stringify( err ) );
            }
        });
    }

    // 上拉加载
    function pullLoading(){
      api.addEventListener({
        name: 'scrolltobottom',
        extra: {
          threshold: 0
        }
      }, function(ret, err){
        history_integral(1);
      });
    }

    // 下拉刷新
    function initRefresh() {
    api.setRefreshHeaderInfo({
        visible: true,
        // loadingImg: 'widget://image/gril.png',
        bgColor: '#ccc',
        textColor: '#fff',
        textDown: '下拉刷新...',
        textUp: '松开刷新...',
        showTime: true
    }, function(ret, err){
        history_integral();
    });
    }
    

    function templateFun(data,more){
        var wallet1 = $api.byId('wallet-record');
        var wallet2 = $api.byId('list-id');       
        wallet1.style.display='none';
        wallet2.style.display='block';
        var wallet = $api.byId('wallet-list-id');
        var dotFn = doT.template(wallet.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list-id');
        // $api.html(list, html);
        if (more) {
            if (data.length) {
              $api.append(list, html);
            }else{
             api.toast({
              msg: '没有啦！',
              duration: 2000,
              location: 'bottom'
            });
             return; 
            }
        }else{
          // if (data.length) {
           $api.html(list, html);
          // }
        }
    }
        
    function closeWin(){
        api.closeWin({
        });
    }
</script>
</html>